import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,
		userInfo: {},
		logistics: {}, // 物流商品地址信息
		load: false, //自定义加载
	},
	mutations: {
		login(state, provider) {
			state.hasLogin = true;
			state.userInfo = provider;
			uni.setStorage({ //缓存用户登陆信息及状态
				key: 'userInfo',
				data: provider
			})
		},
		updateUserInfo(state, data){
			state.userInfo = data;
			uni.setStorage({
				key: 'userInfo',
				data: data
			})
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({
				key: 'userInfo'
			})
			uni.removeStorage({
				key: 'secret_key'
			})
			uni.removeStorage({
				key: 'selectAddress'
			});
			uni.removeStorage({
				key: 'cartList'
			});
			uni.removeStorage({
				key: 'buylist'
			})
		},
		// 物流商品地址信息
		setlogistics(state, data) {
			state.logistics = data
			uni.setStorage({
				key: 'logistics',
				data: data
			})
		},
		
		show_loading(state){
			state.load = true
		},
		
		hide_loading(state){
			state.load = false
		}
	},
	actions: {

	}
})

export default store
